using Game.Networking.Utils;
using TMPro;
using UnityEngine.UI;

namespace Game.UI {
	public class CreateCodeFileWindow : UIWindow {
		public Button ConfirmButton;

		public TMP_Text       Title;
		public TMP_Text       Description;
		public TMP_InputField InputField;

		IComputingUnitUserDataProvider _dataProvider;

		protected override void Awake() {
			base.Awake();

			var isServer = NetworkOptions.StartServer;
			if ( isServer ) {
				_dataProvider = new ServerComputingUnitUserDataProvider();
			}
			else {
				_dataProvider = new ClientComputingUnitUserDataProvider();
			}
			ConfirmButton.onClick.RemoveAllListeners();
			ConfirmButton.onClick.AddListener(OnComfirmButtonClick);
		}

		void OnComfirmButtonClick() {
			if ( !string.IsNullOrEmpty(InputField.text) ) {
				_dataProvider.CreateNewCodeFile(InputField.text, string.Empty);
			}
			HideWindow();
		}
	}
}
